# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgbase=unrar
pkgname=('unrar' 'libunrar' 'libunrar-devel')
pkgver=5.8.3
pkgrel=1
arch=('i686' 'x86_64')
groups=('base-devel')
url="https://www.rarlab.com/rar_add.htm"
license=('custom')
options=('staticlibs' '!makeflags')
depends=('gcc-libs')
source=("https://www.rarlab.com/rar/unrarsrc-${pkgver}.tar.gz"
        'build-dll.patch')
sha256sums=('3591685c8f5bbcb0be09de3d0a0544adb88966b9cccb80986f6cd2b534fd91a6'
            'ce66744fc6d73bf9bb4f90d1789addb8fe4504897777e771f56b754074a8c988')

prepare() {
  cd ${pkgname}
  patch -p1 -i ${srcdir}/build-dll.patch

  #autoreconf -fi
}

build() {
  cd ${pkgname}
  cp -a ${srcdir}/unrar ${srcdir}/libunrar
  make -C "${srcdir}"/libunrar lib CXXFLAGS="${CXXFLAGS}"
  make CXXFLAGS="${CXXFLAGS}" STRIP="true"
}

package_unrar() {
  pkgdesc="The RAR uncompression program"
  depends=('gcc-libs')
  cd "${srcdir}/${pkgbase}"
  install -Dm755 unrar.exe "${pkgdir}/usr/bin/unrar.exe"
  # install license
  install -Dm644 license.txt "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

package_libunrar() {
  pkgdesc="Library file for applications that use libunrar"
  depends=('gcc-libs')
  cd "${srcdir}/libunrar"
  install -Dm755 msys-unrar.dll "${pkgdir}/usr/bin/msys-unrar.dll"
  # install license
  install -Dm644 license.txt "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

package_libunrar-devel() {
  pkgdesc="Import library and header file for applications that use libunrar"
  depends=('libunrar')
  cd "${srcdir}/libunrar"
  install -Dm644 libunrar.dll.a "${pkgdir}/usr/lib/libunrar.dll.a"
  install -Dm644 libunrar.a "${pkgdir}/usr/lib/libunrar.a"
  install -Dm644 dll.hpp "${pkgdir}/usr/include/unrar/dll.hpp"
}
